package vip.zhenzicheng.test.juc.atomic;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author zhenzicheng
 * @date 2022-09-06 09:59
 */
@Slf4j
public class AtomicUserCase {

  public static void main(String[] args) {
    AtomicReference<User> atomicReference = new AtomicReference<>();
    User zhangsan = new User("zhangsan", 22);
    User lisi = new User("lisi", 24);
    atomicReference.set(zhangsan);
    log.info("更新状态: {}, 当前原子引用类型: {}", atomicReference.compareAndSet(zhangsan, lisi), atomicReference.get());
    log.info("更新状态: {}, 当前原子引用类型: {}", atomicReference.compareAndSet(zhangsan, lisi), atomicReference.get());
  }
}

@AllArgsConstructor
@Data
class User {

  private String username;
  private int age;
}
